/*
 * File:                TestRequestRouter.cs
 * Authors:             
 * Company:             Sandia National Laboratories
 * Project:             
 *
 * Copyright 2008, Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
 * or on behalf of the U.S. Government. Export of this program may require a
 * license from the United States Government. See CopyrightHistory.txt for
 * complete details.
 *
 * Reviewers:
 * Review Date:
 * Review Comments:
 *
 * Revision History:
 *
 * $Log: TestRequestRouter.cs,v $
 * Revision 1.1  2008/10/31 20:52:13  bstitus
 * New testing classes.  Bug #1264
 *
 *
 */

using System;
using System.Collections.Generic;
using System.Text;

using Sandia.MVCFramework.Common;
using Sandia.MVCFramework.Request;

/*
 * 1) Track the last routed request
 * 2) Trach the last synchronously routed request
 * 3) Keep a queue of all of the routed requests
 * 4) Keep a queue of all of the synchronously
 *      routed requests
 * 3) Track the last added routing request
 * 4) Keep a queue of all of the added 
 *      request routings.  Once a routing
 *      request is added, it is never removed
 *      from the queue, instead it is added
 *      to the queue of removed routing requets.
 * 5) Track the last removed routing request
 * 6) Keep a queue of all of the removed
 *      routing requests
 */
namespace Sandia.MVCFramework.Test
{
    /// <summary>
    /// A class to help test request routing
    /// </summary>
    public class TestRequestRouter : IRequestRouter
    {
        IRequest lastRequest;
        IRequest lastSynchronousRequest;

        List<IRequest> allRoutedRequests;
        List<IRequest> allSynchronousRoutedRequests;

        Dictionary<Type, IRequestProcessor> addedRequestRoutings;
        Dictionary<Type, IRequestProcessor> removedRequestRoutings;

        /// <summary>
        /// The last request
        /// </summary>
        protected IRequest LastRequest
        {
            //Read-only
            //
            get { return lastRequest; }
        }

        /// <summary>
        /// The last synchronous request
        /// </summary>
        protected IRequest LastSynchronousRequest
        {
            //Read-only
            //
            get { return lastSynchronousRequest; }
        }

        /// <summary>
        /// All of the routed requests
        /// </summary>
        protected List<IRequest> AllRoutedRequests
        {
            //Read-only
            //
            get { return allRoutedRequests; }
        }

        /// <summary>
        /// All of the synchronously routed requests
        /// </summary>
        protected List<IRequest> AllSynchronousRoutedRequests
        {
            //Read-only
            //
            get { return allSynchronousRoutedRequests; }
        }

        /// <summary>
        /// The added request routings, even if remove was called
        /// </summary>
        protected Dictionary<Type, IRequestProcessor> AddedRequestRoutings
        {
            //Read-only
            //
            get { return addedRequestRoutings; }
        }

        /// <summary>
        /// The removed request routings
        /// </summary>
        protected Dictionary<Type, IRequestProcessor> RemovedRequestRoutings
        {
            //Read-only
            //
            get { return removedRequestRoutings; }
        }

        /// <summary>
        /// Class constructor
        /// </summary>
        protected TestRequestRouter()
        {
            //Initialize this class

            allRoutedRequests = new List<IRequest>();
            allSynchronousRoutedRequests = new List<IRequest>();

            addedRequestRoutings = new Dictionary<Type, IRequestProcessor>();
            removedRequestRoutings = new Dictionary<Type, IRequestProcessor>();
        }

        #region IRequestRouter Members

        /// <summary>
        /// Keep the last routed request
        /// </summary>
        /// <param name="request"></param>
        public void RouteRequest(IRequest request)
        {
            //Save the request
            //
            lastRequest = request;

            //Add the request to the collection
            //
            allRoutedRequests.Add(request);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        public void RouteRequestSynchronously(IRequest request)
        {
            //Save the request
            //
            lastSynchronousRequest = request;

            //Add the request to the collection
            //
            allSynchronousRoutedRequests.Add(request);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestType"></param>
        /// <param name="requestProcessor"></param>
        public void AddRequestRouting(Type requestType, IRequestProcessor requestProcessor)
        {
            //Add the request routing to the collection
            //
            addedRequestRoutings.Add(requestType, requestProcessor);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestType"></param>
        /// <param name="requestProcessor"></param>
        public void RemoveRequestRouting(Type requestType, IRequestProcessor requestProcessor)
        {
            //Add the request routing to the collection
            //
            removedRequestRoutings.Add(requestType, requestProcessor);
        }

        #endregion

        /// <summary>
        /// 
        /// </summary>
        public void clearAddedRoutings()
        {
            //Remove all of the entries in the collection
            //
            addedRequestRoutings.Clear();
        }

        /// <summary>
        /// 
        /// </summary>
        public void clearRemovedRoutings()
        {
            //Remove all of the entries in the collection
            //
            removedRequestRoutings.Clear();
        }
    }
}
